package com.jsu.springboot_medicine.controller;

import com.jsu.springboot_medicine.common.Result;
import com.jsu.springboot_medicine.common.StatusCode;
import com.jsu.springboot_medicine.entity.Report;
import com.jsu.springboot_medicine.entity.User;
import com.jsu.springboot_medicine.service.ReportService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author js
 * @name ReportController
 * @Date 2023/10/2 20:08
 */
@RestController
@RequestMapping("/report")
@CrossOrigin
public class ReportController {
    @Resource
    private ReportService reportService;

    @GetMapping
    public Result<List<Report>> selectAll() {
        List<Report> reports = reportService.selectAll();
        return new Result<List<Report>>(true, StatusCode.OK, "查询成功", reports);
    }

    @GetMapping("/{reporterId}")
    public Result<List<Report>> selectAllById(@PathVariable("reporterId") int reporterId) {
        List<Report> reports = reportService.selectAllById(reporterId);
        return new Result<List<Report>>(true, StatusCode.OK, "查询成功", reports);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") int id) {
        reportService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功", null);
    }

    @PostMapping("/add")
    public Result insert(@RequestBody Report report) {
        reportService.insert(report);
        return new Result(true, StatusCode.OK, "插入成功", null);
    }
}
